//
//  PhotoBrowserControl.m
//  FreeTime
//
//  Created by  on 16/9/2.
//  Copyright © 2016年 SRDZ.com. All rights reserved.
//

#import "PhotoBrowserControl.h"
#import "Header.h"
#import "CommentDetailControl.h"
@interface PhotoBrowserControl (){
    UIView * navBarView,* smallBotV;
    UIImageView *bottomView;
    UIScrollView * scrollView;
    BOOL isShow;
    BOOL isAnimation;
}

@end

@implementation PhotoBrowserControl
- (void)viewWillAppear:(BOOL)animated{
//    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
//    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

}
- (void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.barTintColor = HOME_COLOR;
    self.navigationController.navigationBarHidden = NO;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    [self setupUI];
}
#pragma mark -- selfStyle --
- (void)pop{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupUI{
    self.view.backgroundColor = [UIColor blackColor];
    self.navigationItem.title = @"周四 16/09/01 23:15";
    
}
- (void)setupNav{
    isAnimation = NO;
    isShow = YES;
    navBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, 64)];
    navBarView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:navBarView];
    UIImageView * backImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 20, 20)];
    backImage.image = [UIImage imageNamed:@"back"];
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 20, 70, 40);
    //        leftBtn.backgroundColor = [UIColor blueColor];
    [leftBtn addSubview:backImage];
    [leftBtn addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
    [navBarView addSubview:leftBtn];
    UILabel * titleLbl = [ReduceCode creatLabelWithFrame:CGRectMake((WindowWidth-160)/2, 20, 160, 44) title:@"周四 16/09/02 23:15" titleColor:[UIColor whiteColor] font:17 textAlignment:1];
    [navBarView addSubview:titleLbl];
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(WindowWidth-60, 20, 70, 40);
    //        rightBtn.backgroundColor = [UIColor blueColor];
    [rightBtn setTitle:@"发送" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = FONT(14);
//    [rightBtn addTarget:self action:@selector(saveBtn) forControlEvents:UIControlEventTouchUpInside];
    [navBarView addSubview:rightBtn];
    
    NSArray * arr = @[@"123",@"123",@"123"];
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-64)];
    scrollView.contentSize = CGSizeMake(arr.count*WindowWidth, WindowHeight-64);
    scrollView.pagingEnabled = YES;
    for (int i =0; i<arr.count; i++) {
        UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(i*WindowWidth, 0, WindowWidth, WindowHeight)];
        imageV.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPhoto)];
        [imageV addGestureRecognizer:tap];
        imageV.image = [UIImage imageNamed:@"123"];
        [scrollView addSubview:imageV];
    }
    [self.view addSubview:scrollView];
    
    CGFloat h = [ToolUtil customAutoHeigh:@"啦啦啦啦,德玛西亚" width:WindowWidth-20 num:14];
    bottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0, WindowHeight-h-55, WindowWidth, h+55)];
    bottomView.backgroundColor = [UIColor clearColor];
    bottomView.image = [UIImage imageNamed:@"grey_bg_img-1"];
    bottomView.userInteractionEnabled = YES;
    [self.view addSubview:bottomView];

    UILabel * textLbl = [ReduceCode creatLabelWithFrame:CGRectMake(10, 5, WindowWidth-20, h) title:@"啦啦啦啦,德玛西亚" titleColor:[UIColor whiteColor] font:14 textAlignment:0];
    textLbl.numberOfLines = 0;
    [bottomView addSubview:textLbl];
    smallBotV = [[UIView alloc] initWithFrame:CGRectMake(0, bottomView.frame.size.height-40, WindowWidth, 40)];
    smallBotV.backgroundColor = RGB_COLOR(28, 28, 28);
    [bottomView addSubview:smallBotV];

    UIButton * commentBtn = [ReduceCode creatBtnWithFrame:CGRectMake(10, 7.5, 90, 25) imageName:@"123" labelTitle:@"私密评论" isBorder:YES];
    [commentBtn addTarget:self action:@selector(commentBtn) forControlEvents:UIControlEventTouchUpInside];
    [smallBotV addSubview:commentBtn];
    UIButton * likeBtn = [ReduceCode creatBtnWithFrame:CGRectMake(CGRectGetMaxX(commentBtn.frame)+10, 7.5, 65, 25) imageName:@"123" labelTitle:@"喜欢" isBorder:YES];
    
    [likeBtn addTarget:self action:@selector(likeBtn) forControlEvents:UIControlEventTouchUpInside];
    [smallBotV addSubview:likeBtn];
    CGFloat w = [ToolUtil autoWidth:@"23" width:0 height:25 num:12];
    UIButton * likeBtn1 = [ReduceCode creatBtnWithFrame:CGRectMake(WindowWidth-w-40, 7.5, w+30, 25) imageName:@"123" labelTitle:@"23" isBorder:NO];
    likeBtn1.backgroundColor = [UIColor blueColor];
    [likeBtn1 addTarget:self action:@selector(commentAndLike) forControlEvents:UIControlEventTouchUpInside];
    [smallBotV addSubview:likeBtn1];
    UIButton * commentBtn1 = [ReduceCode creatBtnWithFrame:CGRectMake(likeBtn1.frame.origin.x-w-30, 7.5, w+30, 25) imageName:@"123" labelTitle:@"23" isBorder:NO];
    
    [commentBtn1 addTarget:self action:@selector(commentAndLike) forControlEvents:UIControlEventTouchUpInside];
    [smallBotV addSubview:commentBtn1];
    
    
    
    
}

#pragma mark -- 手势事件 -- 
- (void)tapPhoto{
    if (isAnimation) {
        return;
    }
    [UIView animateWithDuration:0.5 animations:^{
        isAnimation = YES;
        if (isShow) {
            navBarView.transform = CGAffineTransformMakeTranslation(0, -64);
            bottomView.transform = CGAffineTransformMakeTranslation(0, 40);
            [[UIApplication sharedApplication] setStatusBarHidden:YES];
        }else{
            navBarView.transform = CGAffineTransformIdentity;
            bottomView.transform = CGAffineTransformIdentity;
            [[UIApplication sharedApplication] setStatusBarHidden:NO];
        }
        isShow =!isShow;
    }completion:^(BOOL finished) {
        isAnimation = NO;
    }];
}
#pragma mark -- button响应事件 -- 
- (void)commentBtn{
    
}
- (void)likeBtn{
    
}
- (void)commentAndLike{
    [self.navigationController pushViewController:[CommentDetailControl new] animated:YES];
}
@end
